require.config({
    baseUrl:"./js/modules-list",
    paths:{
        jq: "../libs/jquery.2.2.4",
        getJson: "../public/getJson",
        render: "render",
        setLocal: "setLocal",
        pagination:"jquery.pagination"
    }
})

require(["jq","getJson","render","setLocal" ],function(_, gj, r, sl){
    gj({
        url:"../json/goods-list.json"
    }).then((res)=>{
        // 渲染页面
        // $(".pagination").pagination(2, {
        //     items_per_page: 1,
        //     num_display_entries: 4,
        //     num_edge_entries: 3,
        //     current_page: 0,
        //     prev_text: "上一页",
        //     next_text: "下一页",
        //     ellipse_text: "----",
        //     prev_show_always: false,
        //     callback: function (index) {
        //     }
        //   });
        r({
            res:JSON.parse(res),
            cont:$(".cont")
        })
    })

    // 绑定点击事件
    $(".cont").on("click",".add",function(){
        if (document.cookie.split("=")[2] != 2) {
            if (confirm("亲，您还没有登陆，是否去登录？")) {
              location.href = "./login.html";
            } else {
              location.href = "./index.html";
            }
            return;
          }
        let id = $(this).parent().attr("index");
        let price = $(this).parent().find("h2").find("span").html()-0;
        let weight =$(this).attr("we")
        // 要将：id,num,weight，flag,price，存储到localStorage
        sl({id, price, num:1,weight,flag:0});
    })
})

